<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="车辆品牌" prop="carBrand">
        <el-input v-model="queryParams.carBrand" placeholder="请输入" clearable style="width: 140px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="车架号" prop="frameNum">
        <el-input v-model="queryParams.frameNum" placeholder="请输入" clearable style="width: 200px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="借款订单编号" prop="id">
        <el-input v-model="queryParams.id" placeholder="请输入" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="客户姓名" prop="clientName">
        <el-input v-model="queryParams.clientName" placeholder="请输入" clearable style="width: 150px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="手机号" prop="clientPhone">
        <el-input v-model="queryParams.clientPhone" placeholder="请输入" clearable style="width: 140px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="状态" prop="disposalStatus">
        <el-select 
          v-model="queryParams.disposalStatus" 
          placeholder="全部" 
          clearable 
          style="width: 100px">
          <el-option 
            v-for="dict in dict.type.car_manager_disposal_status" 
            :key="dict.value" 
            :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="carList" @selection-change="handleSelectionChange">
      
      <el-table-column label="借款订单编号" prop="id" width="100" />
      <el-table-column label="车辆品牌" prop="carBrand" :show-overflow-tooltip="true" width="80" />
      <el-table-column label="车架号" prop="frameNum" :show-overflow-tooltip="true" width="100" />
      <el-table-column label="来源渠道" prop="source" width="100" />
      <el-table-column label="处置状态" prop="disposalStatus" width="80" />
      <el-table-column label="车身颜色" prop="carColor" width="70" />
      <el-table-column label="客户姓名" prop="clientName" width="80" />
      <el-table-column label="客户手机号" prop="clientPhone" width="160" />
      <el-table-column label="创建时间" prop="createTime" width="200" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime)}}</span>
        </template>
      </el-table-column>
      

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">

        <template slot-scope="scope">
        <router-link :to="'/pledge/carManagement/carManage/index/' + scope.row.id" class="link-type">
      <el-button icon="el-icon-user"
                >查看</el-button>

        </router-link>

      </template>

      </el-table-column>
    </el-table>

    <pagination 
      v-show="total>0" 
      :total="total" 
      :page.sync="queryParams.pageNum" 
      :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>

import {findAll} from '@/api/pledge/carManagement';


export default {
  dicts: ['car_manager_disposal_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      carList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 数据范围选项
      dataScopeOptions: [
        {
          value: "1",
          label: "全部数据权限"
        },
        {
          value: "2",
          label: "自定数据权限"
        },
        {
          value: "3",
          label: "本部门数据权限"
        },
        {
          value: "4",
          label: "本部门及以下数据权限"
        },
        {
          value: "5",
          label: "仅本人数据权限"
        }
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined,
        id: undefined,
        carBrand: undefined,
        frameNum: undefined,
        source: undefined,
        disposalStatus: undefined,
        carColor: undefined,
        clientName: undefined,
        clientPhone: undefined,
        createTime: undefined
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" }
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" }
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查看用户操作 */
    // handleA() {

    //   this.$router.push("/pledge/carManagement/carManage/index");
    // },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      findAll(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.carList = response.rows;
        this.total = response.total;
        this.loading = false;
      }
      );
    },
    
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
      
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roleId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    
    /** 导出按钮操作 */
    handleExport() {
      this.download('carManagement/export', {
        ...this.queryParams
      }, `车辆管理信息_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>